{block name=classterm-panel}
{* Define the function *} {function name=render_class_form } 
	{if $selectClassOption eq 'move'}
		<input type="hidden" value="" name="classterm[{$item.classterm_id}][id]" class="value" id="classterm{$item.classterm_id}"> 
		<input class="chckbx" type="checkbox" name="ct-checkbox" onclick="if($(this).is(':checked')){ $(this).parent().children('.value').val('{$item.classterm_id}') }else{ $(this).parent().children('.value').val('0') }" id="ct-ckbox{$item.classterm_id}">
		{$item.class_start_time|date_format:"%I.%M%p"|lower}
		<div class="agegroup">{$item.agegroup_shortname}</div>
		<span>[{$item.availability.taken}/{$item.availability.size}]</span>
	
	{elseif $selectClassOption eq 'makeup' || $selectClassOption eq 'movetrial'} 
		<select name="classterm[{$item.classterm_id}][attr][week]" class="makeup-week{$item.classterm_id}" onchange="$('.makeup-week{$item.classterm_id}').val(this.value)">
			<option value="0">-</option>
			{foreach $item.availability.weeks as $key => $wk}
				<option value="{$wk}">{$item.availability.dates.$key}</option>
			{/foreach}
		</select>
		<br>
		{$item.class_start_time|date_format:"%I.%M%p"|lower}
		<div class="agegroup">{$item.agegroup_shortname}</div>
		<span class="classsize">[{$item.availability.taken}/{$item.availability.size}]</span>
	
	{else}
		<form id="class-form{$item.classterm_id}" class="class-forms timeag" data-attr-id="class-form"  role="form" accept-charset="UTF-8" action="" method="post">
			<input type="hidden" value="AddClassToCart" name="action" id="action" /> 
			<input type="hidden" name="formToken" value="{$token}" />
			<input type="hidden" value="{$item.classterm_id}" name="product_id" id="product_id" /> 
			<input type="hidden" value="1" name="isClass" id="isClass" /> 
			<input type="hidden" value="{if $type}{$type}{else}S{/if}" name="enrolment" class="enrolment-type" />
			<input type="hidden" value="1" name="quantity" id="quantity">
			
			{foreach $item.availability.weeks as $wk}
				<input type="hidden" class="" value="{$wk}" name="attr[week][]" id="week_value{$wk}" />
			{/foreach}
			
			<div class="single-session is-trial" {if $type neq 'T'}style="display:none;"{/if}>
				<select name="trial[attr][week][0]" class="trial-week{$item.classterm_id}" onchange="$('.trial-week{$item.classterm_id}').val(this.value)">
					{foreach $item.availability.weeks as $key => $wk}
						<option value="{$wk}">{$item.availability.dates.$key|date_format:"%Y-%m-%d"}</option>
					{/foreach}
				</select>
			</div>
			{assign var='sessions' value=count($item.availability.weeks)}
			{if $item.class_special_price gt 0}
				{assign var='classtotal' value=$sessions*$item.class_special_price}
			{else}
				{assign var='classtotal' value=$sessions*$item.class_price}
			{/if}
			<input type="hidden" value="{$classtotal}" name="price" id="price" /> 
						
			<a {if $item.availability.available lt 3  && $item.availability.available gt 2}class="almost"{elseif $item.availability.available eq 0}class="full"{/if} href="javascript:void(0)" onclick="$(this).closest('form').submit();">
				{$item.class_start_time|date_format:"%I.%M%p"|lower}
				<div class="agegroup">{$item.agegroup_shortname}</div>
				<span class="classsize">[{$item.availability.taken}/{$item.availability.size}]</span>
			</a>
		</form>	
	{/if}
{/function}

<div id="result">
	{if $classes}
	<div class="row">
		<div class="col-sm-12 text-center">
			{if $location }
				<b>{$location}</b> 的场馆及课程
			{/if}
		</div>
	</div>
	
	<div class="row">
	
<!-- Nav tabs -->
	<ul class="nav nav-tabs" role="tablist" id="tabs">
		{foreach from=$terms key=key item=val name=tarr}
			{if $smarty.foreach.tarr.first}
				{assign var='hasLocation' value=0}
				{foreach $classes as $termOID => $termArr}
					{if $termOID eq $val.term_object_id}{foreach $termArr as $locOID => $locArr}{assign var='hasLocation' value=1}{break}{/foreach}{/if}
				{/foreach}
				<li class="{if $hasLocation eq 1}active{/if}">
					<a href="#term3" role="tab" data-toggle="tab">{$val.term_name}</a>
				</li>
			{/if}
			{if !$smarty.foreach.tarr.first && $smarty.foreach.tarr.last}
				<li class="{if $hasLocation neq 1}active{/if}">
					<a href="#term4" role="tab" data-toggle="tab">{$val.term_name}</a>
				</li>
			{/if}
		{/foreach}
	</ul>
	
	
	<div class="tab-content">
		{foreach from=$terms key=key item=val name=tarr}
			{if $smarty.foreach.tarr.first}
				<div class="tab-pane tpborder {if $hasLocation eq 1}active{/if}" id="term3">
					<div class="{if $hasLocation eq 1}visible-xs{else}hide{/if}">
					<div class="row" id="monday">
						<div class="col-sm-12">Monday</div>
					</div>
					<div class="row" id="tuesday">
						<div class="col-sm-12">Tuesday</div>
					</div>
					<div class="row" id="wednesday">
						<div class="col-sm-12">Wednesday</div>
					</div>
					<div class="row" id="thursday">
						<div class="col-sm-12">Thursday</div>
					</div>
					<div class="row" id="friday">
						<div class="col-sm-12">Friday</div>
					</div>
					<div class="row" id="saturday">
						<div class="col-sm-12">Saturday</div>
					</div>
					<div class="row" id="sunday">
						<div class="col-sm-12">Sunday</div>
					</div>
					</div>
				{if $hasLocation neq 1}<div class="visible-xs text-center"><b>This term just ended</b></div>{/if}
				
					<table id="resulttable" class="hidden-xs">
					<thead class="{if $hasLocation neq 1}hide{/if}">
						<tr>
						<th></th>
						<th colspan="2">Mon</th>
						<th colspan="2">Tue</th>
						<th colspan="2">Wed</th>
						<th colspan="2">Thur</th>
						<th colspan="2">Fri</th>
						<th colspan="2">Sat</th>
						<th colspan="2">Sun</th>
						</tr>
					</thead>
					<tbody>
						{if $hasLocation neq 1}<tr><td style="text-align:center!important;line-height:30px;"><b>This term just ended.</b></td></tr>{/if}
						{foreach $classes as $termOID => $termArr}
							{if $termOID eq $val.term_object_id}
								{foreach $termArr as $locOID => $locArr}
									<tr>
										<td>
											<div class="hidden-xs location-name">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Monday -->
											{if $locArr.Monday}
												{foreach from=$locArr.Monday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
													{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Tuesday -->
											{if $locArr.Tuesday}
												{foreach from=$locArr.Tuesday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Wednesday -->
											{if $locArr.Wednesday}
												{foreach from=$locArr.Wednesday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Thursday -->
											{if $locArr.Thursday}
												{foreach from=$locArr.Thursday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Friday -->
											{if $locArr.Friday}
												{foreach from=$locArr.Friday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Saturday -->
											{if $locArr.Saturday}
												{foreach from=$locArr.Saturday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td> 
										<td>	<!--Sunday -->
											{if $locArr.Sunday}
												{foreach from=$locArr.Sunday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
									</tr>
								{/foreach}
							{/if}
						{/foreach}
					</tbody>
					</table>
				</div>
			{/if}
			
			{if !$smarty.foreach.tarr.first && $smarty.foreach.tarr.last}
				<div class="tab-pane tpborder {if $hasLocation neq 1}active{/if}" id="term4">
					<div class="visible-xs">
					<div class="row" id="monday1">
						<div class="col-sm-12">Monday</div>
					</div>
					<div class="row" id="tuesday1">
						<div class="col-sm-12">Tuesday</div>
					</div>
					<div class="row" id="wednesday1">
						<div class="col-sm-12">Wednesday</div>
					</div>
					<div class="row" id="thursday1">
						<div class="col-sm-12">Thursday</div>
					</div>
					<div class="row" id="friday1">
						<div class="col-sm-12">Friday</div>
					</div>
					<div class="row" id="saturday1">
						<div class="col-sm-12">Saturday</div>
					</div>
					<div class="row" id="sunday1">
						<div class="col-sm-12">Sunday</div>
					</div>
					</div>
				
				
					<table id="resulttable1" class="hidden-xs">
					<thead>
						<tr>
						<th></th>
						<th colspan="2">Mon</th>
						<th colspan="2">Tue</th>
						<th colspan="2">Wed</th>
						<th colspan="2">Thur</th>
						<th colspan="2">Fri</th>
						<th colspan="2">Sat</th>
						<th colspan="2">Sun</th>
						</tr>
					</thead>
					<tbody>
						{foreach $classes as $termOID => $termArr}
							{if $termOID eq $val.term_object_id}
								{foreach $termArr as $locOID => $locArr}
									<tr>
										<td>
											<div class="hidden-xs location-name">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Monday -->
											{if $locArr.Monday}
												{foreach from=$locArr.Monday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Tuesday -->
											{if $locArr.Tuesday}
												{foreach from=$locArr.Tuesday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Wednesday -->
											{if $locArr.Wednesday}
												{foreach from=$locArr.Wednesday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Thursday -->
											{if $locArr.Thursday}
												{foreach from=$locArr.Thursday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Friday -->
											{if $locArr.Friday}
												{foreach from=$locArr.Friday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td>
										<td><!-- Saturday -->
											{if $locArr.Saturday}
												{foreach from=$locArr.Saturday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
										<td>
											<div class="visible-xs">
												<div><b>{$locArr.location_suburb_state}</b></div><div class="small">{$locArr.location_name}</div>
												<div class="small">{$locArr.location_address}</div>
											</div>
										</td> 
										<td>	<!--Sunday -->
											{if $locArr.Sunday}
												{foreach from=$locArr.Sunday key=classk item=item name=classArr}
													{if !$smarty.foreach.classArr.first}<hr>{/if}
														{call name=render_class_form item=$item}
												{/foreach}
											{else}
												-
											{/if}
										</td>
									</tr>
								{/foreach}	
							{/if}
						{/foreach}
					</tbody>
					</table>
				</div>
			{/if}
		{/foreach}
	</div>
	
	
	</div>
	{else}
		<div class="row">
		{if $search_age || $search_suburb || $search_postcode}
		<div class="col-sm-12 text-center text-danger">
				<h3>No classes found {if $search_age}for <b>{$search_age} year olds</b>{/if} {if $search_suburb || $search_postcode}in suburbs around {if $search_suburb}<b>{$search_suburb}</b>{elseif $search_postcode}postcode <b>{$search_postcode}</b>{/if}{/if}</h3>
		</div>
		{/if}
	</div>
	{/if}
</div>






<script type="text/javascript">
jQuery(document).ready(function($){  

	$('.class-forms').each(function(){
		$(this).validate({
		onkeyup: false,
		});
	});
	
  $('#tabs a').click(function (e) {
  e.preventDefault();
  $(this).tab('show');
  });
  
  var colValues = [];
  var colValues1 = [];

  var colno;

  $("#term3 tbody>tr").each(function(i){
   colValues[i]=[];
   for (colno=0;colno<15;colno=colno+2){
   		colValues[i][colno] = $('#term3 tr:nth-child('+(i+1)+')>td:nth-child('+(colno+2)+')').html();
   		colValues[i][colno+1] = $('#term3 tr:nth-child('+(i+1)+')>td:nth-child('+(colno+3)+')').html();
   }
   });
   var rows=$("#term3 tbody>tr").length;

   for(j=0;j<15;j=j+2){
   var count=0;
   $("#term3 tbody>tr").each(function(i){
   var test=colValues[i][j+1];
   if (test === undefined){
	}else{
		   test=test.trim();
   }
   if(test=='-'){
   	count++;
   }else{
   		chk=j/2;
   		switch(chk){
   			case 0:
   				$("#monday").append("<div class='col-xs-6'>"+colValues[i][j]+"</div><div class='col-xs-6'>"+colValues[i][j+1]+"</div>");
   				break;
   			case 1:
   				$("#tuesday").append("<div class='col-xs-6'>"+colValues[i][j]+"</div><div class='col-xs-6'>"+colValues[i][j+1]+"</div>");

   				break;
   			case 2:
   				$("#wednesday").append("<div class='col-xs-6'>"+colValues[i][j]+"</div><div class='col-xs-6'>"+colValues[i][j+1]+"</div>");

   				break;
   			case 3:
   				$("#thursday").append("<div class='col-xs-6'>"+colValues[i][j]+"</div><div class='col-xs-6'>"+colValues[i][j+1]+"</div>");
				
   				break;
   			case 4:
   				$("#friday").append("<div class='col-xs-6'>"+colValues[i][j]+"</div><div class='col-xs-6'>"+colValues[i][j+1]+"</div>");

   				break;
   			case 5:
   				$("#saturday").append("<div class='col-xs-6'>"+colValues[i][j]+"</div><div class='col-xs-6'>"+colValues[i][j+1]+"</div>");

   				break;
   			case 6:
   				$("#sunday").append("<div class='col-xs-6'>"+colValues[i][j]+"</div><div class='col-xs-6'>"+colValues[i][j+1]+"</div>");
   		}
   }
   if(count==rows){
      		chk=j/2;
   		switch(chk){
   			case 0:
   				$("#monday").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");
   				break;
   			case 1:
   				$("#tuesday").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");

   				break;
   			case 2:
   				$("#wednesday").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");

   				break;
   			case 3:
   				$("#thursday").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");
				
   				break;
   			case 4:
   				$("#friday").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");

   				break;
   			case 5:
   				$("#saturday").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");

   				break;
   			case 6:
   				$("#sunday").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");
   		}
   }
   
   });
   }

  $("#term4 tbody>tr").each(function(i){
   colValues1[i]=[];
   for (colno=0;colno<15;colno=colno+2){
   		colValues1[i][colno] = $('#term4 tr:nth-child('+(i+1)+')>td:nth-child('+(colno+2)+')').html();
   		colValues1[i][colno+1] = $('#term4 tr:nth-child('+(i+1)+')>td:nth-child('+(colno+3)+')').html();
   }
   });
   
   var rows=$("#term4 tbody>tr").length;

   for(j=0;j<15;j=j+2){
   var count=0;
   $("#term4 tbody>tr").each(function(i){
   var test=colValues1[i][j+1];
   if (test === undefined){
	}else{
		   test=test.trim();
   }
   if(test=='-'){
   	count++;
   }else{
   		chk=j/2;
   		switch(chk){
   			case 0:
   				$("#monday1").append("<div class='col-xs-6'>"+colValues1[i][j]+"</div><div class='col-xs-6'>"+colValues1[i][j+1]+"</div>");
   				break;
   			case 1:
   				$("#tuesday1").append("<div class='col-xs-6'>"+colValues1[i][j]+"</div><div class='col-xs-6'>"+colValues1[i][j+1]+"</div>");

   				break;
   			case 2:
   				$("#wednesday1").append("<div class='col-xs-6'>"+colValues1[i][j]+"</div><div class='col-xs-6'>"+colValues1[i][j+1]+"</div>");

   				break;
   			case 3:
   				$("#thursday1").append("<div class='col-xs-6'>"+colValues1[i][j]+"</div><div class='col-xs-6'>"+colValues1[i][j+1]+"</div>");
				
   				break;
   			case 4:
   				$("#friday1").append("<div class='col-xs-6'>"+colValues1[i][j]+"</div><div class='col-xs-6'>"+colValues1[i][j+1]+"</div>");

   				break;
   			case 5:
   				$("#saturday1").append("<div class='col-xs-6'>"+colValues1[i][j]+"</div><div class='col-xs-6'>"+colValues1[i][j+1]+"</div>");

   				break;
   			case 6:
   				$("#sunday1").append("<div class='col-xs-6'>"+colValues1[i][j]+"</div><div class='col-xs-6'>"+colValues1[i][j+1]+"</div>");

   				break;

   		}
   }
/*    alert(count); */
   if(count==rows){
      	chk=j/2;
   		switch(chk){
   			case 0:
   				$("#monday1").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");
   				break;
   			case 1:
   				$("#tuesday1").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");

   				break;
   			case 2:
   				$("#wednesday1").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");

   				break;
   			case 3:
   				$("#thursday1").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");
				
   				break;
   			case 4:
   				$("#friday1").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");

   				break;
   			case 5:
   				$("#saturday1").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");

   				break;
   			case 6:
   				$("#sunday1").append("<div class='row'><div class='col-xs-12'>No classes scheduled</div></div>");
   		}
   }
   
   });
   }


});

</script>
{/block}